//
//  CYCompanyInfoTableVC.m
//  CreditAddressBook
//
//  Created by LE on 15/12/25.
//  Copyright © 2015年 Lee. All rights reserved.
//

#import "CYCompanyInfoTableVC.h"
#import "CYCompanyUserTool.h"
#import "UIImageView+WebCache.h"
#import "CYDiscoveryHttpTool.h"
#import "LEMDLib.h"
#import "CYJumpsTool.h"

@interface CYCompanyInfoTableVC ()

@property (weak, nonatomic) IBOutlet UILabel *phoneLabel;
@property (weak, nonatomic) IBOutlet UILabel *userType;
@property (weak, nonatomic) IBOutlet UILabel *userStatus;
@property (weak, nonatomic) IBOutlet UIImageView *idCardZIV;
@property (weak, nonatomic) IBOutlet UIImageView *idCardFIV;
@property (weak, nonatomic) IBOutlet UIImageView *licenseIV;

@property(nonatomic, strong) CYCompanyUserModel *companyUser;
@end

@implementation CYCompanyInfoTableVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initData];
    [self setupItem];
}

- (void)initData {
    CYCompanyUserModel *user = [CYCompanyUserTool companyUser];
    if (user) {
        self.companyUser = user;
        self.phoneLabel.text = user.phone;
        self.userStatus.text = user.examineStatusName;
        self.userType.text = @"企业用户";
        if (user.legalLicenseZAddress && !user.legalLicenseZAddress.isEmpty) {
            [self.idCardZIV sd_setImageWithURL:CYURLWithUserService(user.legalLicenseZAddress) placeholderImage:[UIImage imageNamed:@""]];
        }
        if (user.legalLicenseFAddress && !user.legalLicenseFAddress.isEmpty) {
            [self.idCardZIV sd_setImageWithURL:CYURLWithUserService(user.legalLicenseFAddress) placeholderImage:[UIImage imageNamed:@""]];
        }
        if (user.licenseAddress && !user.licenseAddress.isEmpty) {
            [self.idCardZIV sd_setImageWithURL:CYURLWithUserService(user.licenseAddress) placeholderImage:[UIImage imageNamed:@""]];
        }
    }
}

- (void)setupItem {
    if (self.pushType == CYPushTypePresent) {
        UIBarButtonItem *cancel = [[UIBarButtonItem alloc] initWithTitle:@"取消" style:UIBarButtonItemStylePlain target:self action:@selector(cancel)];
        self.navigationItem.rightBarButtonItem = cancel;
        
        UIBarButtonItem *logout = [[UIBarButtonItem alloc] initWithTitle:@"登出" style:UIBarButtonItemStylePlain target:self action:@selector(logout)];
        self.navigationItem.leftBarButtonItem = logout;
    } else {
        UIBarButtonItem *logout = [[UIBarButtonItem alloc] initWithTitle:@"登出" style:UIBarButtonItemStylePlain target:self action:@selector(logout)];
        self.navigationItem.rightBarButtonItem = logout;
    }
}

- (void)cancel {
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)logout {
    [CYCompanyUserTool logout];
    [CYJumpsTool jumpToMain:self.view];
}

- (IBAction)userStatusBtn:(UIButton *)sender {
    if (self.companyUser.examineStatus.intValue != 1 && self.companyUser.examineStatus.intValue != 2) {
        
    }
}

#pragma mark - UITabelViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    return 8;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    return .1f;
}
@end
